package jmine.tec.persist.jms.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import jmine.tec.persist.annotation.Alias;

import org.hibernate.annotations.Type;

import bancosys.tec.component.Documentation;
import bancosys.tec.persist.bussobj.PersistableBusinessObject;
import bancosys.tec.utils.date.Timestamp;

/**
 * Entidade para persistir mensagens recebidas via JMS.
 * 
 * @author takeshi
 */
@Entity
@Table(name = "JMS_MESSAGE")
@Alias("JMSMSG")
@SequenceGenerator(name = "SEQ_JMSMSG", sequenceName = "SEQ_JMSMSG")
@Documentation("ARMAZENA MENSAGENS JMS")
public class JMSStoredMessage extends PersistableBusinessObject {

    private Long id;

    private byte[] message;

    private Timestamp receiveTime = new Timestamp(), lastProcessed = new Timestamp();

    private String errorMessage;

    private String listenerBeanName;

    /**
     * @return the id
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_JMSMSG")
    @Column(name = "COD_JMS_MSG", nullable = false)
    @Documentation("CODIGO DA MENSAGEM JMS.")
    public Long getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the message
     */
    @Lob
    @Column(name = "MSG", nullable = false)
    @Documentation("A MENSAGEM ARMAZENADA.")
    public byte[] getMessage() {
        byte[] mensagem = message;
        return mensagem;
    }

    /**
     * @param message the message to set
     */
    public void setMessage(byte[] message) {
        this.message = message;
    }

    /**
     * @return the timestamp
     */
    @Column(name = "TS_MSG_RECEIVE", nullable = false)
    @Type(type = "bancosys.tec.persist.hibernate.type.TimestampType")
    @Documentation("TIMESTAMP NA QUAL A MENSAGEM CHEGOU.")
    public Timestamp getReceiveTime() {
        return receiveTime;
    }

    /**
     * @param timestamp the timestamp to set
     */
    public void setReceiveTime(Timestamp timestamp) {
        this.receiveTime = timestamp;
    }

    /**
     * @return the errorMessage
     */
    @Column(name = "ERROR_MSG", length = 10485760)
    @Type(type = "org.hibernate.type.TextType")
    @Documentation("DETALHE DO ERRO.")
    public String getErrorMessage() {
        return errorMessage;
    }

    /**
     * @param errorMessage the errorMessage to set
     */
    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    /**
     * @return the listenerBeanName
     */
    @Column(name = "LISTENER_NAME")
    @Documentation("IDENTIFICACAO INTERNA DO LISTENER DE MENSAGENS")
    public String getListenerBeanName() {
        return listenerBeanName;
    }

    /**
     * @param listenerBeanName the listenerBeanName to set
     */
    public void setListenerBeanName(String listenerBeanName) {
        this.listenerBeanName = listenerBeanName;
    }

    /**
     * @return the lastProcessed
     */
    @Column(name = "TS_MSG_PROCESS", nullable = false)
    @Type(type = "bancosys.tec.persist.hibernate.type.TimestampType")
    @Documentation("TIMESTAMP DA ULTIMA VEZ QUE A MENSAGEM FOI PROCESSADA.")
    public Timestamp getLastProcessed() {
        return lastProcessed;
    }

    /**
     * @param lastProcessed the lastProcessed to set
     */
    public void setLastProcessed(Timestamp lastProcessed) {
        this.lastProcessed = lastProcessed;
    }

}
